﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace GolfSigma.Inventory.Model
{
    public class GetSearchRequest : IRequest
    {
        public UInt64 SearchId { get; set; }

        public GetSearchRequest()
        {
            SearchId = 0;
        }
        public GetSearchRequest(UInt64 searchId)
        {
            SearchId = searchId;
        }

        #region IRequest Members

        public string HttpVerb
        {
            get { return "GET"; }
        }

        public string HttpPath
        {
            get { return "/search/" + SearchId.ToString() + ".xml"; }
        }

        public IDictionary<string, string> HttpParameters
        {
            get { return null; }
        }

        public IDictionary<string, string> HttpHeaders
        {
            get { return null; }
        }

        #endregion
    }

    [XmlRoot("Response")]
    public class GetSearchResponse
    {
        [XmlElement("Search")]
        public Search Search { get; set; }

        [XmlElement("ResponseMetadata")]
        public ResponseMetadata ResponseMetadata { get; set; }
    }

    public class GetRecentSearchRequest : IRequest
    {
        public string ExternalId { get; set; }
        public int Limit { get; set; }

        public GetRecentSearchRequest()
        {
            ExternalId = string.Empty;
        }
        public GetRecentSearchRequest(string externalId)
        {
            ExternalId = externalId;
        }

        #region IRequest Members

        public string HttpVerb
        {
            get { return "GET"; }
        }

        public string HttpPath
        {
            get 
            { 
                var query = "/search/byexternalid/" + System.Web.HttpUtility.UrlEncode(ExternalId) + ".xml";

                // Add the limit
                if (Limit > 0)
                    query += "?l=" + Limit.ToString();

                return query;
            }
        }

        public IDictionary<string, string> HttpParameters
        {
            get { return null; }
        }

        public IDictionary<string, string> HttpHeaders
        {
            get { return null; }
        }

        #endregion
    }

    [XmlRoot("Response")]
    public class GetRecentSearchResponse
    {
        [XmlArray("Searches")]
        public List<Search> Searches { get; set; }

        [XmlElement("ResponseMetadata")]
        public ResponseMetadata ResponseMetadata { get; set; }
    }
}
